define(function(require, exports, module) {
	var $ = require("jquery");
	function Location() {
		this.items	= {
		'0':{4825:'台灣'},
		'0,4825':{256:'基隆市',257:'臺北市',258:'新北市',259:'宜蘭縣',260:'新竹市',261:'新竹縣',262:'桃園市',263:'苗栗縣',264:'臺中市',265:'彰化縣',266:'南投縣',267:'嘉義市',268:'嘉義縣',269:'雲林縣',270:'臺南市',271:'高雄市',272:'屏東縣',273:'臺東縣',274:'花蓮縣',275:'金門縣',276:'連江縣',277:'澎湖縣'},
		'0,4825,256':{4239:'仁愛區',4240:'信義區',4241:'中正區',4242:'中山區',4243:'安樂區',4244:'暖暖區',4245:'七堵區'},
		'0,4825,257':{4246:'中正區',4247:'大同區',4248:'中山區',4249:'松山區',4250:'大安區',4251:'萬華區',4252:'信義區',4253:'士林區',4254:'北投區',4255:'內湖區',4256:'南港區',4257:'文山區'},
		'0,4825,258':{4258:'萬里區',4259:'金山區',4260:'板橋區',4261:'汐止區',4262:'深坑區',4263:'石碇區',4264:'瑞芳區',4265:'平溪區',4266:'雙溪區',4267:'貢寮區',4268:'新店區',4269:'坪林區',4270:'烏來區',4271:'永和區',4272:'中和區',4273:'土城區',4274:'三峽區',4275:'樹林區',4276:'鶯歌區',4277:'三重區',4278:'新莊區',4279:'泰山區',4280:'林口區',4281:'蘆洲區',4282:'五股區',4283:'八里區',4284:'淡水區',4285:'三芝區',4286:'石門區'},
		'0,4825,259':{4287:'宜蘭市',4288:'頭城鎮',4289:'礁溪鄉',4290:'壯圍鄉',4291:'員山鄉',4292:'羅東鎮',4293:'三星鄉',4294:'大同鄉',4295:'五結鄉',4296:'冬山鄉',4297:'蘇澳鎮',4298:'南澳鄉'},
		'0,4825,260':{4299:'東區',4300:'北區',4301:'香山區'},
		'0,4825,261':{4302:'竹北市',4303:'湖口鄉',4304:'新豐鄉',4305:'新埔鎮',4306:'關西鎮',4307:'芎林鄉',4308:'寶山鄉',4309:'竹東鎮',4310:'五峰鄉',4311:'橫山鄉',4312:'尖石鄉',4313:'北埔鄉',4314:'峨嵋鄉'},
		'0,4825,262':{4315:'中壢區',4316:'平鎮區',4317:'龍潭區',4318:'楊梅區',4319:'新屋區',4320:'觀音區',4321:'桃園區',4322:'龜山區',4323:'八德區',4324:'大溪區',4325:'復興區',4326:'大園區',4327:'蘆竹區'},
		'0,4825,263':{4328:'竹南鎮',4329:'頭份市',4330:'三灣鄉',4331:'南庄鄉',4332:'獅潭鄉',4333:'後龍鎮',4334:'通霄鎮',4335:'苑裡鎮',4336:'苗栗市',4337:'造橋鄉',4338:'頭屋鄉',4339:'公館鄉',4340:'大湖鄉',4341:'泰安鄉',4342:'銅鑼鄉',4343:'三義鄉',4344:'西湖鄉',4345:'卓蘭鎮'},
		'0,4825,264':{4346:'中區',4347:'東區',4348:'南區',4349:'西區',4350:'北區',4351:'北屯區',4352:'西屯區',4353:'南屯區',4354:'太平區',4355:'大里區',4356:'霧峰區',4357:'烏日區',4358:'豐原區',4359:'后里區',4360:'石岡區',4361:'東勢區',4362:'和平區',4363:'新社區',4364:'潭子區',4365:'大雅區',4366:'神岡區',4367:'大肚區',4368:'沙鹿區',4369:'龍井區',4370:'梧棲區',4371:'清水區',4372:'大甲區',4373:'外埔區',4374:'大安區'},
		'0,4825,265':{4375:'彰化市',4376:'芬園鄉',4377:'花壇鄉',4378:'秀水鄉',4379:'鹿港鎮',4380:'福興鄉',4381:'線西鄉',4382:'和美鎮',4383:'伸港鄉',4384:'員林市',4385:'社頭鄉',4386:'永靖鄉',4387:'埔心鄉',4388:'溪湖鎮',4389:'大村鄉',4390:'埔鹽鄉',4391:'田中鎮',4392:'北斗鎮',4393:'田尾鄉',4394:'埤頭鄉',4395:'溪州鄉',4396:'竹塘鄉',4397:'二林鎮',4398:'大城鄉',4399:'芳苑鄉',4400:'二水鄉'},
		'0,4825,266':{4401:'南投市',4402:'中寮鄉',4403:'草屯鎮',4404:'國姓鄉',4405:'埔里鎮',4406:'仁愛鄉',4407:'名間鄉',4408:'集集鎮',4409:'水里鄉',4410:'魚池鄉',4411:'信義鄉',4412:'竹山鎮',4413:'鹿谷鄉'},
		'0,4825,267':{4414:'東區',4415:'西區'},
		'0,4825,268':{4416:'番路鄉',4417:'梅山鄉',4418:'竹崎鄉',4419:'阿里山',4420:'中埔鄉',4421:'大埔鄉',4422:'水上鄉',4423:'鹿草鄉',4424:'太保市',4425:'朴子市',4426:'東石鄉',4427:'六腳鄉',4428:'新港鄉',4429:'民雄鄉',4430:'大林鎮',4431:'溪口鄉',4432:'義竹鄉',4433:'布袋鎮'},
		'0,4825,269':{4434:'斗南鎮',4435:'大埤鄉',4436:'虎尾鎮',4437:'土庫鎮',4438:'褒忠鄉',4439:'東勢鄉',4440:'臺西鄉',4441:'崙背鄉',4442:'麥寮鄉',4443:'斗六市',4444:'林內鄉',4445:'古坑鄉',4446:'莿桐鄉',4447:'西螺鎮',4448:'二崙鄉',4449:'北港鎮',4450:'水林鄉',4451:'口湖鄉',4452:'四湖鄉',4453:'元長鄉'},
		'0,4825,270':{4454:'中西區',4455:'東區',4456:'南區',4457:'北區',4458:'安平區',4459:'安南區',4460:'永康區',4461:'歸仁區',4462:'新化區',4463:'左鎮區',4464:'玉井區',4465:'楠西區',4466:'南化區',4467:'仁德區',4468:'關廟區',4469:'龍崎區',4470:'官田區',4471:'麻豆區',4472:'佳里區',4473:'西港區',4474:'七股區',4475:'將軍區',4476:'學甲區',4477:'北門區',4478:'新營區',4479:'後壁區',4480:'白河區',4481:'東山區',4482:'六甲區',4483:'下營區',4484:'柳營區',4485:'鹽水區',4486:'善化區',4487:'大內區',4488:'山上區',4489:'新市區',4490:'安定區'},
		'0,4825,271':{4491:'新興區',4492:'前金區',4493:'苓雅區',4494:'鹽埕區',4495:'鼓山區',4496:'旗津區',4497:'前鎮區',4498:'三民區',4499:'楠梓區',4500:'小港區',4501:'左營區',4502:'仁武區',4503:'大社區',4504:'岡山區',4505:'路竹區',4506:'阿蓮區',4507:'田寮區',4508:'燕巢區',4509:'橋頭區',4510:'梓官區',4511:'彌陀區',4512:'永安區',4513:'湖內區',4514:'鳳山區',4515:'大寮區',4516:'林園區',4517:'鳥松區',4518:'大樹區',4519:'旗山區',4520:'美濃區',4521:'六龜區',4522:'內門區',4523:'杉林區',4524:'甲仙區',4525:'桃源區',4526:'那瑪夏區',4527:'茂林區',4528:'茄萣區'},
		'0,4825,272':{4529:'屏東市',4530:'三地門鄉',4531:'霧臺鄉',4532:'瑪家鄉',4533:'九如鄉',4534:'里港鄉',4535:'高樹鄉',4536:'鹽埔鄉',4537:'長治鄉',4538:'麟洛鄉',4539:'竹田鄉',4540:'內埔鄉',4541:'萬丹鄉',4542:'潮州鎮',4543:'泰武鄉',4544:'來義鄉',4545:'萬巒鄉',4546:'崁頂鄉',4547:'新埤鄉',4548:'南州鄉',4549:'林邊鄉',4550:'東港鎮',4551:'琉球鄉',4552:'佳冬鄉',4553:'新園鄉',4554:'枋寮鄉',4555:'枋山鄉',4556:'春日鄉',4557:'獅子鄉',4558:'車城鄉',4559:'牡丹鄉',4560:'恆春鎮',4561:'滿州鄉'},
		'0,4825,273':{4562:'臺東市',4563:'延平鄉',4564:'卑南鄉',4565:'鹿野鄉',4566:'關山鎮',4567:'海端鄉',4568:'池上鄉',4569:'東河鄉',4570:'成功鎮',4571:'長濱鄉',4572:'太麻里鄉',4573:'金峰鄉',4574:'大武鄉',4575:'達仁鄉'},
		'0,4825,274':{4576:'花蓮市',4577:'新城鄉',4578:'秀林鄉',4579:'吉安鄉',4580:'壽豐鄉',4581:'鳳林鎮',4582:'光復鄉',4583:'豐濱鄉',4584:'瑞穗鄉',4585:'萬榮鄉',4586:'玉里鎮',4587:'卓溪鄉',4588:'富里鄉'},
		'0,4825,275':{4589:'金沙鎮',4590:'金湖鎮',4591:'金寧鄉',4592:'金城鎮'},
		'0,4825,276':{4593:'南竿鄉',4594:'北竿鄉',4595:'莒光鄉',4596:'東引鄉'},
		'0,4825,277':{4597:'西嶼鄉',4598:'七美鄉',4599:'湖西鄉'}
		};
	}

	Location.prototype.find	= function(id) {
		if(typeof(this.items[id]) == "undefined")
			return false;
		return this.items[id];
	}

	Location.prototype.fillOption = function(el_id , loc_id , selected_id) {
		var el	= $('#'+el_id); 
		var json	= this.find(loc_id); 
		if (json) {
			var index	= 1;
			var selected_index	= 0;
			$.each(json , function(k , v) {
				if(v=='台灣'){
					var option	= '<option value="'+k+'|'+v+'" selected="selected" >'+v+'</option>';
				}else{
					
					var option	= '<option value="'+k+'|'+v+'" >'+v+'</option>';
				}
				
				el.append(option);
				
				if (k == selected_id) {
					selected_index	= index;
				}
				
				index++;
			})
		}
	}
	function showLocation(province , city ,town) {
		
		var loc	= new Location();
		var title	= ['地區' , '市' , '區'];
		$.each(title , function(k , v) {
			title[k]	= '<option value="">'+v+'</option>';
		})
		
		var pid = $('#province'),cid = $('#city'),aid = $('#area');
		pid.append(title[0]);
		cid.append(title[1]);
		aid.append(title[2]);
		
		pid.change(function() {
			cid.empty();
			cid.append(title[1]);
			
			var provinceVal = pid.val().split('|');
			console.log(provinceVal);
			loc.fillOption('city' , '0,'+provinceVal[0]);
			cid.change()
		})
		
		cid.change(function() {
			aid.empty();
			aid.append(title[2]);
			
			var provinceVal = pid.val().split('|');
			var cityVal = cid.val().split('|');
			loc.fillOption('area' , '0,' + provinceVal[0] + ',' + cityVal[0]);
		})
		

		if (province) {
			var provinceArr = province.split('|');province = provinceArr[0];
			loc.fillOption('province' , '0' , province);
			
			if (city) {
				var cityArr = city.split('|');city = cityArr[0];
				loc.fillOption('city' , '0,'+province , city);
				
				if (town) {
					var townArr = town.split('|');town = townArr[0];
					loc.fillOption('area' , '0,'+province+','+city , town);
				}
			}
			
		} else {
			loc.fillOption('province' , '0');
		}
			
	}
	$(function(){ showLocation("4825|台灣","256|基隆市","4239|仁愛區"); })

});